#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //QLineEdit * lineedit=new QLineEdit(this);
    //lineedit->setText(QString("hello world"));

    mybutton=new QPushButton(this);
    mybutton->setText(QString("hello world"));

    mybutton->move(5,5);

    connect(ui->helloButton,&QPushButton::clicked,this,&Widget::HeadleClick);
    //mybutton第一个参数--父类对象传入子类指针--切片
    connect(mybutton,&QPushButton::clicked,this,&Widget::close);

    connect(ui->helloButton_2,&QPushButton::clicked,this,&Widget::HeadleClick3);

    connect(this,&Widget::myClicked,this,&Widget::headleMyClicked);

    //emit 发送信号关键字--可以省略
    //emit 提升可读性
    //emit myClicked();
    myClicked();

    //带参数的信号
    connect(this,&Widget::myClicked2,this,&Widget::headleMyClicked2);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::HeadleClick()
{
    if(ui->helloButton->text()==QString("hello world"))
    {
        ui->helloButton->setText("hello qt");
    }
    else
    {
        ui->helloButton->setText("hello world");
    }
}

void Widget::HeadleClick2()
{
    if(mybutton->text()==QString("hello world"))
    {
        mybutton->setText("hello qt");
    }
    else
    {
        mybutton->setText("hello world");
    }
}

void Widget::HeadleClick3()
{
    this->setWindowTitle("test modify HeadleClick3");
}

void Widget::headleMyClicked()
{
    this->setWindowTitle("test modify headleMyClicked");
}

void Widget::headleMyClicked2(QString & text)
{
    this->setWindowTitle(text);
}

void Widget::on_pushButton_clicked()
{
    this->setWindowTitle("test modify on_pushButton_clicked");
}

void Widget::on_pushButton_2_clicked()
{
    emit myClicked();
}

void Widget::on_pushButton_3_clicked()
{
    QString qString = ui->pushButton_3->text();
    emit myClicked2(qString);
}
